﻿//using Magicodes.ExporterAndImporter.Core;
//using Magicodes.ExporterAndImporter.Excel;
using MiniExcelLibs;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
//using XiaoShuTong.Model;

namespace XiaoShuTong
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //public IImporter Importer = new ExcelImporter();

        List<Article> _articles = new List<Article>();

        public MainWindow()
        {
            InitializeComponent();

        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var datas = _articles.Where(c => c.queryName.Contains(title.Text) && c.status == 2);

            foreach (var item in datas)
            {
                item.page += 1;
            }

            data.ItemsSource = datas;
        }

        public List<Article> LoadData()
        {
            var filePath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "data.xlsx");

            var import = MiniExcel.Query<Article>(filePath);

            var wordPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "违禁词.xlsx");
            if (File.Exists(wordPath))
            {
                var words = MiniExcel.Query<Word>(wordPath);

                return import.Where(c => words.All(w => !c.queryName.Contains(w.违禁词))).ToList();
            }

            return import.ToList();
        }

        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            _articles = LoadData();
            data.ItemsSource = _articles;
        }
    }

    public class Article
    {
        //[ImporterHeader(Name = "queryName")]
        public string queryName { get; set; }

        //[ImporterHeader(Name = "status")]
        public int status { get; set; }

        //[ImporterHeader(Name = "cid")]
        public int cid { get; set; }

        //[ImporterHeader(Name = "page")]
        public int page { get; set; }

    }

    public class Word
    {
        public string 违禁词 { get; set; }
    }
}